package com.ivision.dao.impl;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.ivision.dao.StudentDAO;
import com.ivision.domain.Student;

//@Repository("studentDAO")
public class StudentDAOImpl implements StudentDAO {

	private SessionFactory sessionFactory;
	
	
	public int saveStudent(Student student){
//		Session session = sessionFactory.openSession();		
//		getHibernateSession().save(student);
		System.out.println("Starting to saving student to database.......  ");
		
		
		Serializable pkId = getHibernateSession().save(student);
		return ((Integer)pkId).intValue();
		
		
	}
	
	public Student getStudentById(int studentId){
		System.out.println("tring to get student from database.......  ");
//		Session session = sessionFactory.openSession();		
		return (Student)getHibernateSession().get(Student.class, studentId);		
	}
	
	private Session getHibernateSession(){
		return sessionFactory.openSession();
	}
	
	
	
	
	

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
